﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;
using PiscoSourDominio;
using System.Text; 

namespace PiscoSourWeb.Models
{
    public class ModelOrden: IDisposable
    {

        public IEnumerable<Orden> ListarOrdenes()     
        {
            HttpWebRequest req2 = (HttpWebRequest)WebRequest
                    .Create("http://localhost:49781/Services/Ordenes.svc/ListaOrdenes");    
            req2.Method = "GET";
            HttpWebResponse res2 = (HttpWebResponse)req2.GetResponse();
            StreamReader reader2 = new StreamReader(res2.GetResponseStream());
            string ReservaJson2 = reader2.ReadToEnd(); 
            JavaScriptSerializer js2 = new JavaScriptSerializer();
            List<Orden> lista = js2.Deserialize<List<Orden>>(ReservaJson2); 
            return lista;
        }

        public List<Orden> ObtenerOrdenReserva(int intReserva) 
        {
            string strdata = "/" + intReserva;
            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://localhost:49781/Services/Ordenes.svc/OOrdenReserva" + strdata);
            httpReq.Method = "POST";
            httpReq.ContentType = "application/json";

            var Resrp = (HttpWebResponse)httpReq.GetResponse();
            StreamReader strread = new StreamReader(Resrp.GetResponseStream());
            string strJson = strread.ReadToEnd();

            JavaScriptSerializer js = new JavaScriptSerializer();
            List<Orden> objOrden = js.Deserialize<List<Orden>>(strJson);

            return objOrden;            
        }

        public Orden ObtenerOrden(int intOrden)
        {
            string strdata = "/" + intOrden;
            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://localhost:49781/Services/Ordenes.svc/OOrden" + strdata);
            httpReq.Method = "POST";
            httpReq.ContentType = "application/json";

            var Resrp = (HttpWebResponse)httpReq.GetResponse();
            StreamReader strread = new StreamReader(Resrp.GetResponseStream());
            string strJson = strread.ReadToEnd();

            JavaScriptSerializer js = new JavaScriptSerializer();
            Orden objOrden = js.Deserialize<Orden>(strJson);

            return objOrden;
        }
        
        public void Dispose()
        {
            
        }
 
    }

}